package com.chj.redis.lock;


import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class JedisUtils {

	private Jedis jedis;

	private JedisPool jedisPool;

	private String host;

	private int port;

	public JedisUtils() {
		this("127.0.0.1", 6379);
	}

	public JedisUtils(String host, int port) {
		this.host = host;
		this.port = port;
		initialPool();
		jedis = jedisPool.getResource();
	}

	private void initialPool() {
		JedisPoolConfig config = new JedisPoolConfig();
		config.setMaxIdle(20);
		config.setMaxWaitMillis(1000l);
		config.setTestOnBorrow(false);
		jedisPool = new JedisPool(config, host, port);

	}

	public Jedis getJedis() {
		return jedis;
	}

}